package com.betterjr.modules.receivable.dubbo;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.betterjr.common.web.AjaxObject;
import com.betterjr.modules.receivable.IScfReceivableService;
import com.betterjr.modules.receivable.entity.ScfReceivable;
import com.betterjr.modules.receivable.entity.ScfReceivableDO;
import com.betterjr.modules.receivable.service.ScfReceivableDOService;
import com.betterjr.modules.receivable.service.ScfReceivableService;
import com.betterjr.modules.rule.service.RuleServiceDubboFilterInvoker;

@Service(interfaceClass = IScfReceivableService.class)
public class ScfReceivableDubboService implements IScfReceivableService {

    @Autowired
    private ScfReceivableService scfReceivableService;

    @Autowired
    private ScfReceivableDOService receivableService;

    @Override
    public String webSaveModifyReceivable(final Map<String, Object> anMap, final Long anId, final String anFileList,
            final String anOtherFileList) {
        ScfReceivable anReceivable = (ScfReceivable) RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject
                .newOk("应收账款信息编辑成功",
                        scfReceivableService.saveModifyReceivable(anReceivable, anId, anFileList, anOtherFileList))
                .toJson();
    }

    @Override
    public String webQueryReceivable(final Map<String, Object> anMap, final String anIsOnlyNormal, final String anFlag,
            final int anPageNum, final int anPageSize) {
        Map<String, Object> anQueryConditionMap = (Map<String, Object>) RuleServiceDubboFilterInvoker.getInputObj();

        return AjaxObject.newOkWithPage("应收账款查询成功", scfReceivableService.queryReceivable(anQueryConditionMap,
                anIsOnlyNormal, anFlag, anPageNum, anPageSize)).toJson();
    }

    @Override
    public String webFindReceivableList(final Map<String, Object> anMap, final String anIsOnlyNormal) {
        Map<String, Object> queryMap = RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject.newOk("应收账款查询成功", scfReceivableService.findReceivableList(queryMap, anIsOnlyNormal)).toJson();
    }

    @Override
    public String webFindReceivableDetailsById(final Long anId) {
        return AjaxObject.newOk("应收账款详情查询成功", scfReceivableService.findReceivableDetailsById(anId)).toJson();
    }

    @Override
    public String webAddReceivable(final Map<String, Object> anMap, final String anFileList,
            final String anOtherFileList) {
        ScfReceivable anReceivable = (ScfReceivable) RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject
                .newOk("应收账款新增成功", scfReceivableService.addReceivable(anReceivable, anFileList, anOtherFileList))
                .toJson();
    }

    @Override
    public String webSaveAduitReceivable(final Long anId) {

        return AjaxObject.newOk("应收账款审核成功", scfReceivableService.saveAduitReceivable(anId)).toJson();
    }

    @Override
    public String webAddReceivableDO(final Map<String, Object> anAnMap, final String anFileList,
            final boolean anConfirmFlag) {

        ScfReceivableDO receivable = (ScfReceivableDO) RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject.newOk("应收账款新增成功", receivableService.addReceivable(receivable, anFileList, anConfirmFlag))
                .toJson();
    }

    @Override
    public String webSaveModifyReceivableDO(final Map<String, Object> anAnMap, final String anFileList,
            final boolean anConfirmFlag) {

        ScfReceivableDO receivable = (ScfReceivableDO) RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject
                .newOk("应收账款修改成功", receivableService.saveModifyReceivable(receivable, anFileList, anConfirmFlag))
                .toJson();

    }

    @Override
    public String webSaveAnnulReceivable(final String anRefNo, final String anVersion) {
        //
        return AjaxObject.newOk("应收账款废止成功", receivableService.saveAnnulReceivable(anRefNo, anVersion)).toJson();
    }

    @Override
    public String webSaveAuditReceivableByRefNoVersion(final String anRefNo, final String anVersion,
            final Map<String, Object> anAnMap) {

        return AjaxObject.newOk("应收账款审核成功", receivableService.saveAuditReceivable(anRefNo, anVersion, anAnMap))
                .toJson();
    }

    @Override
    public String webFindReceivableByRefNoVersion(final String anRefNo, final String anVersion) {

        return AjaxObject.newOk("应收账款查询成功", receivableService.findReceivable(anRefNo, anVersion)).toJson();
    }

    @Override
    public String webQueryIneffectiveReceivable(final Map<String, Object> anAnMap, final String anFlag,
            final int anPageNum, final int anPageSize, final boolean anIsAudit) {

        Map<String, Object> anQueryConditionMap = (Map<String, Object>) RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject.newOkWithPage("应收账款查询成功", receivableService.queryIneffectiveReceivable(anQueryConditionMap,
                anFlag, anPageNum, anPageSize, anIsAudit)).toJson();

    }

    @Override
    public String webQueryEffectiveReceivable(final Map<String, Object> anAnMap, final String anFlag,
            final int anPageNum, final int anPageSize, final boolean anIsCust) {

        Map<String, Object> anQueryConditionMap = (Map<String, Object>) RuleServiceDubboFilterInvoker.getInputObj();
        return AjaxObject.newOkWithPage("应收账款查询成功", receivableService.queryEffectiveReceivable(anQueryConditionMap,
                anFlag, anPageNum, anPageSize, anIsCust)).toJson();

    }


    @Override
    public String webFindReceivableByRefNoVersion(Long anId) {

        return AjaxObject.newOk("应收账款查询成功", receivableService.findReceivable(anId)).toJson();
	}
    /** 
     * <p>Overriding Method of webQueryNotUserEffectiveReceivable</p>  
     * <p>Description: </p> 
     * @Description: 核心企业，供应商查询生效，未使用应收账款  
     * @param anMap 前端参数    
     * @param anPageNum 页码
     * @param anPageSize 页面数量   
     * @param anFlag    是否统计总数
     * @param anIsCust   true供应商， false核心企业
     * @return 生效,未使用应收账款分页
     * @return 
     * @see com.betterjr.modules.receivable.IScfReceivableService#webQueryNotUserEffectiveReceivable(java.util.Map, int, int, int, boolean) 
     * @author xuzx
     * @date 2017年11月22日 下午4:50:29 
     */
    @Override
    public String webQueryNotUserEffectiveReceivable(final Map<String, Object> anMap, final int anPageNum,
            final int anPageSize, final int anFlag, final boolean anIsCust) {
        // TODO Auto-generated method stub
        return AjaxObject
                .newOkWithPage("分页查询已生效且未使用应收账款成功",
                        receivableService.queryNotUserReceivablePage(anMap, anPageNum, anPageSize, anFlag, anIsCust))
                .toJson();

    }

}
